package com.leetcode.algorithm.y22.m07.w4;

import java.util.PriorityQueue;

/**
 * 1845. 座位预约管理系统
 * 
 * https://leetcode.cn/problems/seat-reservation-manager/
 * 
 * @author jie.deng
 *
 */
class SeatManager {

	private int next = 0;
	private PriorityQueue<Integer> queue;

	public SeatManager(int n) {
		next = 1;
		queue = new PriorityQueue<>();
	}

	public int reserve() {
		if (queue.isEmpty()) {
			return next++;
		}
		return queue.poll().intValue();
	}

	public void unreserve(int seatNumber) {
		queue.offer(seatNumber);
	}
}